<template>
  <div id="main">
    <div style="padding-left: 100px; text-align: left; font-size: 50px; padding-top: 130px;">
      在线阅览室后台管理系统
    </div>
    <div class="box-card">
      <el-card style="background-color: white; height: 400px">
        <div>
          <el-row>
            <div class="hhhh">用户登录</div>
          </el-row>
          <div id="form">
            <el-input v-model="account" placeholder="账号">
              <template slot="prepend">账&nbsp;&nbsp;&nbsp;&nbsp;号</template>
            </el-input>
            <el-input v-model="password" placeholder="密码" type="password">
              <template slot="prepend">密&nbsp;&nbsp;&nbsp;&nbsp;码</template>
            </el-input>
            <el-row>
              <el-col :span="12">
                <el-input v-model="code" placeholder="验证码">
                  <template slot="prepend">验证码</template>
                </el-input>
              </el-col>
              <el-col :span="12">
                <div style="margin-top: 15px;margin-left: 20px;">
                  <img style=" border-radius: 6px" :src="img" alt="" @click="getImg">
                </div>
              </el-col>
            </el-row>
          </div>
          <div style="line-height: 23px;padding-top: 19px; padding-right: 15px; padding-left: 15px;">
            <el-row>
              <div>
                <el-button type="primary" class="butt" style="margin-left: 18px" @click="onSubmit">登录</el-button>
              </div>
            </el-row>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      account: '',
      password: '',
      code: '',
      img: '',
      uuid: ''
    }
  },
  created() {
    this.getImg();
  },
  methods: {
    getImg(){
      this.$axios.get("/api/kaptCha").then(res=>{
        if(res.data.code === '200'){
          this.img = 'data:image/png;base64,'+ res.data.data.img;
          this.uuid = res.data.data.uuid;
        }else{
          this.$message.error(res.data.message);
        }
      })
    },
    onSubmit() {
      this.$axios.post("/api/login", {
        account: this.account,
        password: this.password,
        code: this.code,
        uuid: this.uuid
      }).then(res=>{
        if (res.data.code === '200'){
          localStorage.setItem("loginMes", JSON.stringify(res.data.data));
          this.$router.push("/index");
        }else {
          this.$message.error(res.data.message);
          this.getImg();
        }
      });
      this.uuid = '';
      this.code = '';
    }
  }
}
</script>

<style scoped>
.box-card {
  width: 500px;
  line-height: 557px;
  padding-top: 43px;
  padding-left: 37%;
  padding-bottom: 247px;
}

#main {
  background-image: url('http://yangxiong001.oss-cn-hangzhou.aliyuncs.com/photo/loginbackground.jpg');
  background-size: 100%, 100%;
  position: fixed;
  width: 100%;
  height: 100%;
  padding: 0 20px 40px 20px;
}

#form {
  padding-top: 17px;
  line-height: 72px;
  padding-right: 33px;
  padding-left: 33px;
  top: 10px;
}

.butt {
  line-height: 14px;
  text-align: center;
  width: 91%;
}

.hhhh {
  line-height: 29px;
  text-align: center;
  font-weight: 666;
  color: plum;
  font-size: 30px;
  border-bottom: #d9d9d9 solid 1px;
  padding-bottom: 10px
}
</style>
